package com.youjiang.meeting.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.youjiang.meeting.service.ControlService;
import com.youjiang.meeting.utils.StringKeyValue;

/**
 * <p>
 * Title: ConsoleController
 * </p>
 * <p>
 * Description:控制
 * </p>
 */
@Controller
@RequestMapping(value = "/control", produces = StringKeyValue.CONTROLLERPRODUCES)
public class ConsoleController {
	@Autowired
	private ControlService service;

	@RequestMapping("/start/{name}")
	@ResponseBody
	public String start(HttpSession session,@PathVariable("name") String name, Integer id, HttpServletRequest req) {
		String data = "";
		// 红包开
		if (name.equals("redpack")) {
			data = service.startRed(session,id);
		}
		// 投票
		if (name.equals("voit")) {
			data = service.startVoit(session);
		}
		if (name.equals("game")) {
//			data = service.startGame(id);
		}
		return data;
	}

	@RequestMapping("/end/{name}")
	@ResponseBody
	public String end(HttpSession session,@PathVariable("name") String name, Integer id, HttpServletRequest req) {
		String data = "";
		// 结束红包
		if (name.equals("redpack")) {
			data = service.endRed(session,id);
		}
		// 投票
		if (name.equals("voit")) {
			data = service.endVoid(session);
		}
		if (name.equals("game")) {
			data = service.endGame();
		}
		return data;
	}
	@RequestMapping("/show")
	@ResponseBody
	public String show(HttpSession session,@RequestParam(defaultValue = "0")Integer level,@RequestParam(defaultValue = "0")Integer id){
		return service.showWindow(session,id, level);
	}
	@RequestMapping("/hide")
	@ResponseBody
	public String hide(HttpSession session){
		return service.hideWindow(session);
	}
	@RequestMapping("/rob")
	public String robRedpack(String openid,@RequestParam(defaultValue = "0")Integer redpack,HttpServletRequest req){
		String pack = service.requestRedPack(openid, redpack, req);
		return pack;
	}
	@RequestMapping("/send/redpack")
	@ResponseBody
	public String sendRedPack(String openid,HttpServletRequest req,@RequestParam(defaultValue = "0") Integer id,String money){
		return service.sendRedPack(openid, id, req,money);
	}
	@RequestMapping("/close")
	@ResponseBody
	public String closeWindow(){
		return service.closeWindow();
	}
	@RequestMapping("/reload")
	@ResponseBody
	public String reloadWindow(){
		return service.reloadWindow();
	}
}
